var area = require('../../component/getAddress/getAddress');

var areaInfo = []; //所有省市区县数据

var provinces = []; //省

var provinceNames = []; //省名称

var citys = []; //城市

var cityNames = []; //城市名称

var countys = []; //区县

var countyNames = []; //区县名称

var value = [0, 0, 0]; //数据位置下标

var addressList = null;

Page({
 

  /**

   * 页面的初始数据

   */

  data: {
    transportValues: ["收货时间不限", "周六日/节假日收货", "周一至周五收货"],

    transportIndex: 0,

    provinceIndex: 0, //省份

    cityIndex: 0, //城市

    countyIndex: 0, //区县

    windowHeight: 0,
    // locationArr: ['山东省', '青岛市', '黄岛区']
    locationArr: ['', '', '']
  },
   
    onLoad: function(options) {
      var that = this
      console.log(options)
      //获得dialog组件
      this.getAddress = this.selectComponent("#getAddress");
   
      wx.getSystemInfo({
        success: function(res) {
          console.log(res.pixelRatio) //设备像素比
          console.log(res.windowWidth) //可使用窗口宽度
          console.log(res.windowHeight) //可使用窗口高度
   
          that.setData({
            windowWidth: res.windowWidth, //可使用窗口宽度
            windowHeight: res.windowHeight, //可使用窗口高度
          })
        }
      })
    },
   
   
    //选择地址
    chooseAddress: function(e) {
      var that = this
   
      this.getAddress.showsGoodsDetail();
    },
   
    //组件回调
    resultEvent: function(e) {
      var that = this
   
      console.log(e)
      console.log(e.detail.nameArr)
      that.setData({
        locationArr: e.detail.nameArr
      })
    },
   
 

 

  /**

   * 生命周期函数--监听页面加载

   */


 

  /**

   * 生命周期函数--监听页面显示

   */

  onShow: function() {
  },

 

  bindTransportDayChange: function(e) {
    console.log('picker country 发生选择改变，携带值为', e.detail.value);

    this.setData({
      transportIndex: e.detail.value

    })

  },

 

  bindProvinceNameChange: function(e) {
    var that = this;

    console.log('picker province 发生选择改变，携带值为', e.detail.value);

    var val = e.detail.value

    that.getCityArr(val); //获取地级市数据

    that.getCountyInfo(val, 0); //获取区县数据

 

    value = [val, 0, 0];

    this.setData({
      provinceIndex: e.detail.value,

      cityIndex: 0,

      countyIndex: 0,

      value: value

    })

 

  },

 

  bindCityNameChange: function(e) {
    var that = this;

    console.log('picker city 发生选择改变，携带值为', e.detail.value);

 

    var val = e.detail.value

    that.getCountyInfo(value[0], val); //获取区县数据

    value = [value[0], val, 0];

    this.setData({
      cityIndex: e.detail.value,

      countyIndex: 0,

      value: value

    })

  },

 

  bindCountyNameChange: function(e) {
    var that = this;

    console.log('picker county 发生选择改变，携带值为', e.detail.value);

    this.setData({
      countyIndex: e.detail.value

    })

  },

 

  saveAddress: function(e) {
    var consignee = e.detail.value.consignee;

    var mobile = e.detail.value.mobile;

    var transportDay = e.detail.value.transportDay;

    var provinceName = e.detail.value.provinceName;

    var cityName = e.detail.value.cityName;

    var countyName = e.detail.value.countyName;

    var address = e.detail.value.address;

 

    console.log(transportDay + "," + provinceName + "," + cityName + "," + countyName + "," + address); //输出该文本 

 

    var arr = wx.getStorageSync('addressList') || [];

    console.log("arr,{}", arr);

    addressList = {
      consignee: consignee,

      mobile: mobile,

      address: provinceName + cityName + countyName+address,

      transportDay: transportDay

    }

      arr.push(addressList);

    wx.setStorageSync('addressList', arr);

    wx.navigateBack({
      

    })

  }

})